local sk__tianshang = fk.CreateSkill {

  name = "sk__tianshang",

  tags = {  },

}



sk__tianshang:addEffect(fk.Death, {
  name = "sk__tianshang",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true)
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
      "#sk__tianshang-choose", sk__tianshang.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    local skills = {}
    for _, s in ipairs(player.player_skills) do
      if s:isPlayerSkill(player) and s.visible and s ~= self and not to:hasSkill(s, true) then
        table.insert(skills, s.name)
      end
    end
    if #skills > 0 then
      local result = room:askForCustomDialog(player, sk__tianshang.name,
        "packages/utility/qml/ChooseSkillBox.qml", {
        skills, 1, 1, "#sk__tianshang-choice::"..to.id
      })
      local skill = ""
      if result == "" then
        skill = table.random(skills)
      end
      local choice = result
      if #choice > 0 then
        skill = choice[1]
      else
        skill = table.random(skills)
      end
      room:handleAddLoseSkills(to, skill, nil, true, false)
    end
    if not to.dead then
      room:changeMaxHp(to, 1)
    end
    if to:isWounded() and not to.dead then
      room:recover{
        who = to,
        num = 1,
        recoverBy = player,
        skillName = sk__tianshang.name,
      }
    end
  end,
})

return sk__tianshang